import { CommonUtil } from "@/utils"
import { ITemplateJSON } from "../FormParse/FormParse"

export interface IFormGeneratorExpose {
  getTemplateJSON: () => ITemplateJSON[]
}

export type formType = 'text' | 'password' | 'number' | 'textarea' | 'select' | 'checkbox' | 'radio' | 'datetime' | 'picker' | 'upload'

export const generatorItem = (type: formType): ITemplateJSON | undefined => {
  let modelValue = type + '_' + new Date().getTime() + CommonUtil.getRandomInt(0, 99)
  if (type == 'text') {
    return {
      label: '文本框', modelValue, type: 'input', options: {
        type: 'text', placeholder: '请输入', disabled: false, defaultValue: '', required: false
      }
    }
  }
  if (type == 'password') {
    return {
      label: '密码框', modelValue, type: 'input', options: {
        type: 'password', placeholder: '请输入', disabled: false, defaultValue: '', required: false
      }
    }
  }
  if (type == 'number') {
    return {
      label: '数字框', modelValue, type: 'input', options: {
        type: 'number', placeholder: '请输入', disabled: false, defaultValue: '', required: false, width: '50%'
      }
    }
  }
  if (type == 'textarea') {
    return {
      label: '文本域', modelValue, type: 'textarea', options: {
        type: 'textarea', placeholder: '请输入', disabled: false, defaultValue: '', required: false
      }
    }
  }
  if (type == 'select') {
    return {
      label: '下拉框', modelValue, type: 'select', options: {
        placeholder: '请选择', disabled: false, defaultValue: '', required: false, width: '50%', show: false, children: [
          { name: '选项1', value: '选项1' },
          { name: '选项2', value: '选项2' },
          { name: '选项3', value: '选项3' },
        ]
      }
    }
  }
  if (type == 'checkbox') {
    return {
      label: '多选框', modelValue, type: 'checkbox', options: {
        disabled: false, defaultValue: '', required: false, children: [
          { name: '选项1', value: '选项1', checked: false },
          { name: '选项2', value: '选项2', checked: false },
          { name: '选项3', value: '选项3', checked: false },
        ]
      }
    }
  }
  if (type == 'radio') {
    return {
      label: '单选框', modelValue, type: 'radio', options: {
        disabled: false, defaultValue: '', required: false, children: [
          { name: '选项1', value: '选项1', checked: false },
          { name: '选项2', value: '选项2', checked: false },
          { name: '选项3', value: '选项3', checked: false },
        ]
      }
    }
  }
  if (type == 'datetime') {
    return {
      label: '日期选择器', modelValue, type: 'datetime', options: {
        disabled: false, defaultValue: '', required: false, width: '50%'
      }
    }
  }
}

